package com.zhiyou.crowdfunding.controller;

import com.zhiyou.crowdfunding.util.ImgUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 校验
 * 1、验证码生成
 */
@Controller
@RequestMapping("/verify")
public class VerifyController {

    @RequestMapping("/getCodeImg")
    public void getCodeImg(HttpServletRequest request, HttpServletResponse response) throws IOException {
        ImgUtil.VerifyImg verifyImg= ImgUtil.createVerifyCode();
        HttpSession session = request.getSession();  //保存到session
        session.setAttribute("verificationCode", verifyImg.getCodeStr());
        ImageIO.write(verifyImg.getBfi(), "JPG", response.getOutputStream());  //写到输出流
    }

}
